package com.baboba.rummy.cards;

import java.util.Arrays;
import java.util.List;

public class CardBitMap implements Cloneable{
	private int[] red = new int[13];
	private int[] blue = new int[13];
	private int[] black = new int[13];
	private int[] orange = new int[13];
	private int king = 0;
	private int[][] cardArray = new int[4][];
	
	public CardBitMap(List<Card> cards){
		clearState();
		for (Card card : cards){
			if (card instanceof ColorCard){
				ColorCard colorCard = (ColorCard)card;
				cardArray[colorCard.getColor().ordinal()][colorCard.getNumber()-1]++;
			}else
				king++;
		}
	}
	
	public int getCardBitMap(int color, int number){
		return cardArray[color][number-1];
	}
	
	public void setCardBitMap(int color, int number, int value){
		cardArray[color][number-1] = value;
	}
	
	public void increase(int color, int number){
		cardArray[color][number-1]++;
	}
	
	public void decrease(int color, int number){
		cardArray[color][number-1]--;
	}
	
	public int getKing() {
		return king;
	}

	public void setKing(int king) {
		this.king = king;
	}

	protected void clearState(){
		cardArray[0] = red;
		cardArray[1] = blue;
		cardArray[2] = black;
		cardArray[3] = orange;
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("CardBitMap\r\n");
		
		for (Color color : Color.values()){
			buffer.append(color.name()).append(":\t");
			buffer.append(Arrays.toString(cardArray[color.ordinal()]));
			buffer.append("\r\n");
		}
		
		buffer.append("King:\t").append(king);
		return buffer.toString();
	}
	
	
}
